﻿Public Class DRUGCAUTIONCLASS
    Dim connect As CONDB = CONDB.NewConnection()

    Private SLID As Integer = Nothing
    Private SLABELNAME_TH As String = Nothing
    Private SLABELNAME_EN As String = Nothing
    Private STATUS = Nothing

    Private selectMasslabel As String = "SELECT slid AS 'รหัสฉลากเตือน', slabelname_th AS 'ฉลากเตือนไทย', slabelname_en AS 'ฉลากเตือนอังกฤษ', `status` AS 'สถานะการเปิดใช้งาน' FROM masslabel"

    Public Property SLID_ As Integer
        Get
            Return SLID
        End Get
        Set(value As Integer)
            SLID = value
        End Set
    End Property

    Public Property SLABELNAME_TH_ As String
        Get
            Return SLABELNAME_TH
        End Get
        Set(value As String)
            SLABELNAME_TH = value
        End Set
    End Property

    Public Property SLABELNAME_EN_ As String
        Get
            Return SLABELNAME_EN
        End Get
        Set(value As String)
            SLABELNAME_EN = value
        End Set
    End Property

    Property STATUS_ As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property

    Public Property selectMasslabel_ As String
        Get
            Return selectMasslabel
        End Get
        Set(value As String)
            selectMasslabel = value
        End Set
    End Property

    Public Function insertMasslabel() As Boolean
        If connect.GetTable("SELECT slid FROM masslabel WHERE slabelname_th = '" & SLABELNAME_TH & "' OR slabelname_en = '" & SLABELNAME_EN & "'").Rows.Count > 0 Then
            MsgBox("ไม่สามารถเพิ่มคำเตือนได้ เนื่องจากมีคำเตือนนี้อยู่ในระบบอยู่แล้ว")
            Return False
        Else
            Dim sql As String
            sql = "INSERT INTO masslabel (slabelname_th, slabelname_en, status) VALUES ('" & SLABELNAME_TH & "', '" & SLABELNAME_EN & "', '" & STATUS & "');"

            Try
                connect.BeginTrans()
                connect.ExecuteNonQuery(sql)
                connect.CommitTrans()
                Return True
            Catch ex As Exception
                MsgBox(ex.ToString)
                Return False
            End Try
        End If
    End Function


    Public Function editMasslabel() As Boolean
        Dim sql As String
        sql = "UPDATE masslabel SET slabelname_th = '" & SLABELNAME_TH & "', slabelname_en = '" & SLABELNAME_EN & "', status = '" & STATUS & "' WHERE slid = '" & SLID & "';"

        Try
            connect.BeginTrans()
            connect.ExecuteNonQuery(Sql)
            connect.CommitTrans()
            Return True
        Catch ex As Exception
            MsgBox(ex.ToString)
            Return False
        End Try
    End Function
End Class
